package com.example.demo.phone.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.phone.entity.PhoneDTO;
import com.example.demo.phone.mapper.PhoneMapper;
import com.example.demo.phone.util.HttpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(description = "通用接口")
@RestController
@RequestMapping("/phone")
public class Phone {


    @Autowired
    private PhoneMapper mapper;

    @PostMapping("/lsit")
    @ApiOperation(value = "列表")
    public Object list() {
        List<PhoneDTO> list = mapper.list(null);
        return list;
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public Object add(@RequestBody List<PhoneDTO> list) {
        for (PhoneDTO dto : list) {
            mapper.add(new PhoneDTO(dto.getStore(),dto.getModel(),-1,""));
        }
        return null;
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public Object delete(@RequestBody List<String> list) {
        for (String id : list) {
            mapper.delete(id);
        }
        return null;
    }



}
